﻿@model Bricks.Site.Models.ProphaseFileInfoView
@{
    ViewBag.Title = "编辑文件信息";
    Layout = "~/Views/Shared/_UserPage.cshtml";
}
<script type="text/javascript">
    $(function () {
        $("#PreparationStatus").combobox({
            editable: false, panelHeight: "auto",
            valueField: "DictionaryName",
            textField: "DictionaryName",
            url: "/Dictionary/GetDictionaryByTypeTag?typeTag=PreparationStatus",            
            onSelect: function (record) {
                var value = $("#PreparationStatus").combobox('getValue');
                if (value == '不需要') {
                    $("#PlannedCompletionTime").datebox({ disabled: true });
                    $("#ApprovalNumber").attr("disabled", true);
                    $("#ApprovalTime").datebox({ disabled: true });
                    $("#PlannedCompletionTime").datebox('setValue', '/');
                    $("#ApprovalNumber").val('/');
                    $("#ApprovalTime").datebox('setValue', '/');
                }
                else {
                    $("#PlannedCompletionTime").datebox({ disabled: false });
                    $("#ApprovalNumber").attr("disabled", false);
                    $("#ApprovalTime").datebox({ disabled: false });
                }
            }
        });

        if ($("#hPreparationStatus").val() == '不需要') {
            $("#PlannedCompletionTime").datebox({ disabled: true });
            $("#ApprovalNumber").attr("disabled", true);
            $("#ApprovalTime").datebox({ disabled: true });
        }


        $('#modifyInfoDataGrid').datagrid({
            url: '/ProphaseFileInfo/GetProphaseFileModifyInfoList?pid=' + $('#hID').val(),
            fitColumns: true,
            nowrap: true,
            autoRowHeight: false,
            striped: true,
            collapsible: true,
            pagination: true,
            pageSize: 20,
            rownumbers: true,
            remoteSort: false,
            idField: 'ID',
            singleSelect: true,
            columns: [[
                        { title: 'ID', field: 'ID', hidden: true },
                        { title: 'PID', field: 'PID', hidden: true },
                        {
                            title: '修改时间', field: 'MidifyTime', width: 100, sortable: true
                        },
                        { title: '修改原因', field: 'MidifyReason', width: 300, editor: 'text' },
                        {
                            title: '操作', field: 'Action', width: 70, align: 'center',
                            formatter: function (value, row, index) {
                                if (row.editing) {
                                    var s = '<a href="#" onclick="saverow(' + index + ')">保存</a> ';
                                    var c = '<a href="#" onclick="cancelrow(' + index + ')">取消</a>';
                                    return s + c;
                                } else {
                                    var s = '<a href="#" onclick="editrow(' + index + ')">编辑</a> ';
                                    var c = '<a href="#" onclick="deleterow(this)">删除</a>';
                                    return s + c;
                                }
                            }
                        }
            ]],
            onBeforeEdit: function (index, row) {
                row.editing = true;
                $('#modifyInfoDataGrid').datagrid('refreshRow', index);
            },
            onAfterEdit: function (index, row) {
                row.editing = false;
                $('#modifyInfoDataGrid').datagrid('refreshRow', index);
            },
            onCancelEdit: function (index, row) {
                row.editing = false;
                $('#modifyInfoDataGrid').datagrid('refreshRow', index);
            },
            onDblClickRow: function (index, row) {
                $('#myDataGrid').datagrid('beginEdit', index);
                rowIndex = index;
            },
            toolbar: [{
                id: 'btnAdd',
                text: '新增',
                iconCls: 'icon-application_add',
                handler: function () {
                    var lstModifyInfo = $('#modifyInfoDataGrid').datagrid('getData').rows;
                    var currentDate = new Date()
                    var y = currentDate.getFullYear();
                    var m = currentDate.getMonth() + 1;
                    if (m < 10) {
                        m = "0" + m;
                    }
                    var d = currentDate.getDate();
                    if (d < 10) {
                        d = "0" + d;
                    }
                    var currentDateStr = y + '-' + m + '-' + d;

                    $('#modifyInfoDataGrid').datagrid('insertRow', {
                        index: lstModifyInfo.length,
                        row: {
                            ID: NewGuid(),
                            PID: $("#hID").val(),
                            MidifyTime: currentDateStr,
                            MidifyReason: ''
                        }
                    });
                    var currentIndex = lstModifyInfo.length - 1;
                    $('#modifyInfoDataGrid').datagrid('selectRow', currentIndex);
                    $('#modifyInfoDataGrid').datagrid('beginEdit', currentIndex);
                }
            }]
        });
    });


    function editrow(index) {
        $('#modifyInfoDataGrid').datagrid('beginEdit', index);
    }

    function deleterow(target) {
        $.messager.confirm("提示", "你确定要删除吗?", function (r) {
            if (r) {
                var tr = $(target).closest('tr.datagrid-row');
                var index = parseInt(tr.attr('datagrid-row-index'));
                $('#modifyInfoDataGrid').datagrid('deleteRow', index);
                $('#myBillList').datagrid('acceptChanges');
            }
        });
    }

    function saverow(index) {
        $('#modifyInfoDataGrid').datagrid('endEdit', index);
    }

    function cancelrow(index) {
        $('#modifyInfoDataGrid').datagrid('cancelEdit', index);
    }
</script>
<div class="frombox datagrid-body" style="padding-bottom: 5px;">
    <div class="easyui-layout" style="height:530px;width:100%">
        <div data-options="region:'north'" style="height: 280px;">
            <form id="file-model" method="post">
                <input type="hidden" id="hID" name="ID" value="@Model.ID" />
                <input type="hidden" id="hProjectID" name="ProjectID" value="@Model.ProjectID" />
                <input type="hidden" id="hPreparationStatus" name="ID" value="@Model.PreparationStatus" />
                <table class="datagrid-btable" border="0" cellspacing="0" cellpadding="0">
                    <tr class="datagrid-row">
                        <td class="th">
                            <div class="datagrid-cell">阶段名称</div>
                        </td>
                        <td class="td" colspan="3">
                            <div class="datagrid-cell">
                                <input id="ProjectStageID" name="ProjectStageID" style="width:405px;" value="@Model.ProjectStageID" />
                            </div>
                        </td>
                        <td class="th">
                            <div class="datagrid-cell">编制状况</div>
                        </td>
                        <td class="td">
                            <div class="datagrid-cell">
                                <input id="PreparationStatus" name="PreparationStatus" class="easyui-combobox" value="@Model.PreparationStatus" />
                            </div>
                        </td>
                    </tr>
                    <tr class="datagrid-row">
                        <td class="th">
                            <div class="datagrid-cell">计划完成时间</div>
                        </td>
                        <td class="td">
                            <div class="datagrid-cell">
                                <input id="PlannedCompletionTime" name="PlannedCompletionTime" class="easyui-datebox" value="@Model.PlannedCompletionTime" />
                            </div>
                        </td>
                        <td class="th">
                            <div class="datagrid-cell">批准文号</div>
                        </td>
                        <td class="td">
                            <div class="datagrid-cell">
                                <input id="ApprovalNumber" name="ApprovalNumber" class="easyui-textbox" value="@Model.ApprovalNumber" />
                            </div>
                        </td>
                        <td class="th">
                            <div class="datagrid-cell">批复时间</div>
                        </td>
                        <td class="td">
                            <div class="datagrid-cell">
                                <input id="ApprovalTime" name="ApprovalTime" class="easyui-datebox" value="@Model.ApprovalTime" />
                            </div>
                        </td>
                    </tr>
                    <tr class="datagrid-row">
                        <td class="th">
                            <div class="datagrid-cell">文件名称</div>
                        </td>
                        <td class="td">
                            <div class="datagrid-cell">
                                <input id="FileName" name="FileName" class="easyui-textbox" value="@Model.FileName" />
                            </div>
                        </td>
                        <td class="th">
                            <div class="datagrid-cell">处理人部门</div>
                        </td>
                        <td class="td">
                            <div class="datagrid-cell">
                                <input id="DealPersonOrg" name="DealPersonOrg" value="@Model.DealPersonOrg" />
                            </div>
                        </td>
                        <td class="th">
                            <div class="datagrid-cell">登记时间</div>
                        </td>
                        <td class="td">
                            <div class="datagrid-cell">
                                <input name="DealTime" class="easyui-textbox" value="@Model.DealTime" readonly />
                            </div>
                        </td>
                    </tr>
                    <tr class="datagrid-row">
                        <td class="th">
                            <div class="datagrid-cell">工作内容简述</div>
                        </td>
                        <td class="td" colspan="5">
                            <div class="datagrid-cell">
                                <textarea name="Content" cols="57" rows="5" style="width:640px;">@Model.Content</textarea>
                            </div>
                        </td>
                    </tr>
                    <tr class="datagrid-row">
                        <td class="th">
                            <div class="datagrid-cell">附件</div>
                        </td>
                        <td class="td" colspan="5">
                            <div class="datagrid-cell">
                                @*<textarea name="Attachment" cols="57" rows="5" style="width:640px;">@Model.Attachment</textarea>*@
                                <a href='javascript:void(0)' class='easyui-linkbutton' onclick='$.Upload($("#hID").val(), "ProphaseManagement/ProphaseFileList/Attachment")' data-options='plain:true,iconCls:"icon-blue_lego"'>附件操作</a>
                            </div>
                        </td>
                    </tr>
                </table>
                <input id="hID" name="ID" type="hidden" value="@Model.ID" />
                <input id="hProjectID" name="ProjectID" type="hidden" value="@Model.ProjectID" />
                <input id="hDealPerson" name="DealPerson" type="hidden" value="@Model.DealPerson" />
                <input id="hJsonProphaseFileModifyInfo" name="JsonProphaseFileModifyInfo" type="hidden" value="@Model.JsonProphaseFileModifyInfo" />
            </form>
        </div>
        <div data-options="region:'center'" style="height:300px;">
            <table id="modifyInfoDataGrid" fit="true"></table>
        </div>
    </div>
</div>
